package com.design.mediator;


/**
 * @author leali
 * @title: MediatorClient
 * @projectName design
 * @description: MediatorClient
 * @date 2022/1/3 19:59
 */
public class MediatorClient {
    public static void main(String[] args) {
        //定义中介者对象
        ConcreteMediator mediator = new ConcreteMediator();
        //定义同事对象
        Button button = new Button();
        ListBox listBox = new ListBox();
        ComboBox comboBox = new ComboBox();
        TextBox textBox = new TextBox();

        button.setMediator(mediator);
        listBox.setMediator(mediator);
        comboBox.setMediator(mediator);
        textBox.setMediator(mediator);

        mediator.button = button;
        mediator.listBox = listBox;
        mediator.comboBox = comboBox;
        mediator.textBox = textBox;

        button.changed();
        System.out.println("-----------------------------");
        listBox.changed();

        //用新增具体中介者定义中介者对象
        System.out.println("新增Label测试");
        SubConcreteMediator subConcreteMediator = new SubConcreteMediator();
        Label label = new Label();
        button.setMediator(subConcreteMediator);
        listBox.setMediator(subConcreteMediator);
        comboBox.setMediator(subConcreteMediator);
        textBox.setMediator(subConcreteMediator);

        subConcreteMediator.button = button;
        subConcreteMediator.listBox = listBox;
        subConcreteMediator.comboBox = comboBox;
        subConcreteMediator.textBox = textBox;
        subConcreteMediator.label = label;

        button.changed();
        System.out.println("-----------------------------");
        listBox.changed();
    }
}
